<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册用户</title>
    <script src="/js/jquery/jquery-3.4.1.js"></script>
    <link rel="stylesheet" href="/css/common.css" type="text/css">
    <script src="/js/service/common.js"></script>
    <script>
        function login() {
            let loginId =  $("#loginId").val();
            if(!loginId){
                alert("账号不能为空！");
                return;
            }
            let password = $("#password").val();
            if(!password){
                alert("密码不能为空！");
                return;
            }
            let username = $("#username").val();
            username = username ? username : "新建用户";
            $.ajax({
                url: "/login/register",
                data: JSON.stringify({
                    "loginId": loginId,
                    "password": password,
                    "username":username,
                    "gender":$("input[name=gender]:checked").val(),
                    "age":$("#age").val()
                }),
                contentType: 'application/json',
                type: "POST",
                dataType: "json",
                success: function (json) {
                    if(json.code === 200){
                        window.location.href="/page/index";
                    }else{
                        tipsMessage(json);
                    }
                },
                error: function () {
                    alert("提交失败");
                }
            })
        }
    </script>
</head>
<body>
    <object class="object-top" data="/page/common/login"></object>
    <div style="text-align: center; margin-top: 4%">
        <h1>欢迎注册</h1>
        <form id="form" style="margin-top: 4%">
            <label>账号</label>
            <label>
                <input placeholder="请输入账号" name="loginId" type="text" id="loginId"/>
            </label><br>
            <label>密码</label>
            <label>
                <input placeholder="请输入密码" name="password" type="password" id="password"/>
            </label><br>
            <label>姓名</label>
            <label>
                <input placeholder="请输入姓名" name="username" type="text" id="username"/>
            </label><br>
            <label>性别</label>
            <label>
                <input name="gender" type="radio" value="1001" checked/>男
                <input name="gender" type="radio" value="1002"/>女
            </label><br>
            <label>年龄</label>
            <label>
                <input placeholder="请输入年龄" name="age" type="text" id="age" value="0"/>
            </label><br>
            <label><input type="button" class="btn" value="确定" onclick="login()"></label>
            <label><input type="reset" class="btn" value="重置"></label>
        </form>
        <a href="/page/index">返回登陆</a>
    </div>
</body>
</html>